import anime from 'animejs/lib/anime.es.js';
import { Config } from './config';
import { Tooler } from './tooler';

export class Card{

  id;
  type = 0;
  isChoose = false;
  moveDistance = 0;
  moveTimer = 0;
  indexCol = 0;
  order = 0;
  style = {};

  y = 0;

  constructor(){
    this.id = Tooler.generateRandomId()
    this.style = {
      width: Config.CARD_WIDTH + 'px',
      height: Config.CARD_HEIGHT + 'px',
      transform: 'translate3d(0, ' + this.y + 'px, 0)',
    }
  }

  play(){
    anime({
      targets: this,
      y: this.y + this.moveDistance,
      duration: this.moveTimer,
      easing: 'easeOutQuart',
      // easing: 'easeInQuint',
      // easings: 'linear',
      update: () => {
        this.updateStyle();
      }
    })
  }

  updateStyle(){
    this.style.transform = 'translate3d(0, ' + this.y + 'px, 0)';
  }

  choose(v){
    this.isChoose = v;
  }

  updateOrder() {
    if (this.y > -10 && this.y < Config.GAME_HEIGHT - 10) {
      this.order = Math.round(this.y / Config.CARD_HEIGHT) + Config.CARDS_PER_COL * this.indexCol;
    }
    else {
      this.order = -1
    }

  }

  get isOutside(){
    return this.y > Config.GAME_HEIGHT - 10 || this.y < -10
  }

  get isBottom(){
    return this.y > Config.GAME_HEIGHT - 10
  }
}